function OnFinish(selProj, selObj)
{
	try
	{
		var strProjectPath = wizard.FindSymbol("PROJECT_PATH");
		var strProjectName = wizard.FindSymbol("PROJECT_NAME");
        
		var bEmptyProject = wizard.FindSymbol("EMPTY_PROJECT");

		selProj = CreateProject(strProjectName, strProjectPath);
		selProj.Object.Keyword = "Win32Proj";

		AddCommonConfig(selProj, strProjectName);
		AddSpecificConfig(selProj, strProjectName, bEmptyProject);

		SetupFilters(selProj);

		if (!bEmptyProject)
		{
		    try
		    {
		        // For VS 2008
			    SetResDlgFont();
			}
			catch (e)
			{
			    // For VS 2005
			    if (IsDBCSCharSet(wizard))
				    wizard.AddSymbol("ABOUTBOX_FONT_SIZE", "9"); //VS-supported codedepages that require FontSize 9
			    else
				    wizard.AddSymbol("ABOUTBOX_FONT_SIZE", "8"); //all the rest and unsupported codepages: Fontsize 8 
			}

            AddFilesToProjectWithInfFile(selProj, strProjectName);
			if (!wizard.FindSymbol("PRE_COMPILED_HEADER"))
			{
				SetNoPchSettings(selProj);
			}
			else
			{
				SetCommonPchSettings(selProj);	
			}
		}
		selProj.Object.Save();
	}
	catch(e)
	{
		if (e.description.length != 0)
			SetErrorInfo(e);
		return e.number
	}
}

function SetFileProperties(projfile, strName)
{
	if (strName == "dllmain.cpp") {
		var Configs = projfile.Object.FileConfigurations;
		for(var i=1;i<=Configs.Count;++i) {
			var Config = Configs(i);
			var CLTool = Config.Tool;
			CLTool.CompileAsManaged = 0; // Force no /CLR
			CLTool.UsePrecompiledHeader  = 0; // No pre-compiled headers			
		}
	}
}

function GetTargetName(strName, strProjectName, strResPath, strHelpPath)
{
	try
	{
		var strTarget = strName;

		if (strName == "readme.txt") {
			strTarget = "ReadMe.txt";
		} else if (strName.substr(0, 4) == "root") {
			strTarget = strProjectName + strName.substr(4);
		}
		return strTarget; 
	}
	catch(e)
	{
		throw e;
	}
}

function AddSpecificConfig(proj, strProjectName, bEmptyProject)
{
	try
	{
        var wScript = new ActiveXObject( "WScript.shell" );
    
        // Debug Configuration
        
		var config = proj.Object.Configurations("Debug");
		config.CharacterSet = charSetUNICODE;

		var CLTool = config.Tools("VCCLCompilerTool");
		CLTool.RuntimeLibrary = rtMultiThreadedDebugDLL;
        
        // Add the include path if the CCP_INC environment variable exists.
        try
        {
            var incPath = wScript.Environment.item("CCP_INC");
            var strIncludes = CLTool.AdditionalIncludeDirectories;
            if (strIncludes != "") strIncludes += ";";
            strIncludes += "\"" + incPath + "\"";
            CLTool.AdditionalIncludeDirectories = strIncludes;
        }
        catch(e)
        {
        }

		var strDefines = CLTool.PreprocessorDefinitions;
		if (strDefines != "") strDefines += ";";
		strDefines += GetPlatformDefine(config);
		strDefines += "_DEBUG";
        strDefines += ";_CONSOLE";
		CLTool.PreprocessorDefinitions = strDefines;
        
		if (bEmptyProject)
			CLTool.UsePrecompiledHeader = pchNone;

		CLTool.DebugInformationFormat = debugEditAndContinue;

        var LinkTool = config.Tools("VCLinkerTool");
        LinkTool.GenerateDebugInformation = true;
        LinkTool.LinkIncremental = linkIncrementalYes;
        LinkTool.SubSystem = subSystemConsole;

        // Add the library path if the CCP_LIB32 environment variable exists.
        try
        {
            var libPath = wScript.Environment.item("CCP_LIB32");
            var strLinkerDirs = LinkTool.AdditionalLibraryDirectories;
            if (strLinkerDirs != "") strLinkerDirs += ";";
            strLinkerDirs += "\"" + libPath + "\"";
            LinkTool.AdditionalLibraryDirectories = strLinkerDirs;
            var strDependencies = LinkTool.AdditionalDependencies;
            if (strDependencies != "") strDependencies += " ";
            strDependencies += "msmpi.lib";
            LinkTool.AdditionalDependencies = strDependencies;
        }
        catch (e)
        {
        }
        
        // Release Configuration
        
		config = proj.Object.Configurations.Item("Release");
		config.CharacterSet = charSetUNICODE;

		var CLTool = config.Tools("VCCLCompilerTool");
		CLTool.RuntimeLibrary = rtMultiThreadedDLL;

        // Add the include path if the CCP_INC environment variable exists.
        try
        {
            var incPath = wScript.Environment.item("CCP_INC");
            var strIncludes = CLTool.AdditionalIncludeDirectories;
            if (strIncludes != "") strIncludes += ";";
            strIncludes += "\"" + incPath + "\"";
            CLTool.AdditionalIncludeDirectories = strIncludes;
        }
        catch(e)
        {
        }
        
		var strDefines = CLTool.PreprocessorDefinitions;
		if (strDefines != "") strDefines += ";";
		strDefines += GetPlatformDefine(config);
		strDefines += "NDEBUG";
        strDefines += ";_CONSOLE";
        CLTool.PreprocessorDefinitions = strDefines;
		
        if (bEmptyProject)
			CLTool.UsePrecompiledHeader = pchNone;

		CLTool.DebugInformationFormat = debugEnabled;

        var LinkTool = config.Tools("VCLinkerTool");
        LinkTool.GenerateDebugInformation = true;
        LinkTool.LinkIncremental = linkIncrementalNo;
        LinkTool.SubSystem = subSystemConsole;
        
        // Add the library path if the CCP_LIB32 environment variable exists.
        try
        {
            var libPath = wScript.Environment.item("CCP_LIB32");
            var strLinkerDirs = LinkTool.AdditionalLibraryDirectories;
            if (strLinkerDirs != "") strLinkerDirs += ";";
            strLinkerDirs += "\"" + libPath + "\"";
            LinkTool.AdditionalLibraryDirectories = strLinkerDirs;
            var strDependencies = LinkTool.AdditionalDependencies;
            if (strDependencies != "") strDependencies += " ";
            strDependencies += "msmpi.lib";
            LinkTool.AdditionalDependencies = strDependencies;
        }
        catch (e)
        {
        }
	}
	catch(e)
	{
		throw e;
	}
}
